#!/bin/bash

#build
set -ex
source /etc/profile
#cd /bigbluebutton/bigbluebutton-web && grails war
cd /vagrant/bigbluebutton/bigbluebutton-apps && gradle war

#deploy
set -ex
source /etc/profile
service tomcat7 stop
service bbb-red5 stop
cd /vagrant/bigbluebutton/bigbluebutton-apps && gradle deploy

#all restart
source /etc/profile
security_salt=$(cat /vagrant/conf/development/security_salt)
asj_security_salt=$(cat /vagrant/conf/development/asj_security_salt)
server_host=$(cat /vagrant/conf/development/server_host)
sed -i "s/asjSecuritySalt=.*/asjSecuritySalt=${asj_security_salt}/" /var/lib/tomcat7/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
sed -i "s/aotrs.host=.*/aotrs.host=${server_host}/" /var/lib/tomcat7/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
echo "restart bbb-conf host=$server_host salt=$security_salt asj_security_salt=$asj_security_salt ..."
bbb-conf --clean --setip $server_host --setsecret $security_salt
